import {createStore} from 'vuex'
import persistedState from 'vuex-persistedstate'

import user from './user';
import shop from './shop';
export default createStore({
    state:{
        count:0
    },
    getters:{
        oddOrEven(state){
            return state.count % 2 == 1?"奇数":"偶数"
        }
    },
    // commit
    mutations:{
        add(state,val){
            state.count += val
        }
    },
    // dispatch
    actions:{
        jian({commit,state},val){
            state.count-=val
        }
    },
    modules:{
        user,
        shop
    },
    plugins:[
        persistedState({
            key:'zhilong',//秘钥
            paths:['user']//哪个模块持久化保存数据

        })
    ]
})


/* 
完成vuex 持久化存储  本质都是通过localStorage或sessionStorage
vuex-along
vuex-persisitedstate




*/